﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace QLHPHP
{
    public partial class TimKiemControl : UserControl
    {
        public TimKiemControl()
        {
            InitializeComponent();
        }

        private AppCommands _Commands;

        /// <summary>
        /// Gets or sets the commands associated with the control.
        /// </summary>
        public AppCommands Commands
        {
            get { return _Commands; }
            set
            {
                if (value != _Commands)
                {
                    AppCommands oldValue = _Commands;
                    _Commands = value;
                    OnCommandsChanged(oldValue, value);
                }
            }
        }
        /// <summary>
        /// Called when Commands property has changed.
        /// </summary>
        /// <param name="oldValue">Old property value</param>
        /// <param name="newValue">New property value</param>
        protected virtual void OnCommandsChanged(AppCommands oldValue, AppCommands newValue)
        {
            if (newValue != null)
            {
                btnClose.Command = newValue.TimKiemCommands.Cancel;
                
            }
            else
            {
                btnClose.Command = null;
                
            }
        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            if (txtNoiDung.Text == "")
            {
                ToastNotification.Show(this, "Vui lòng nhập nội dung cần tìm");
            }
            else
            {
                switch (cbbTimTheo.Text)
                { 
                    case "Họ tên":
                        dgvDSTK.DataSource = TimKiem.TimKiemTheoHoTen(txtNoiDung.Text);
                        break;
                    case "Mã số sinh viên":
                        dgvDSTK.DataSource = TimKiem.TimKiemTheoMSSV(txtNoiDung.Text);
                        break;
                    case "Giới tính":
                        dgvDSTK.DataSource = TimKiem.TimKiemTheoGioiTinh(txtNoiDung.Text);
                        break;
                    case "Tên huyện":
                        dgvDSTK.DataSource = TimKiem.TimKiemTheoTenHuyen(txtNoiDung.Text);
                        break;
                    case "Tên ngành":
                        dgvDSTK.DataSource = TimKiem.TimKiemTheoTenNganh(txtNoiDung.Text);
                        break;
                    case "Tên khoa":
                        dgvDSTK.DataSource = TimKiem.TimKiemTheoTenKhoa(txtNoiDung.Text);
                        break;
                    case "Mã đối tượng":
                        dgvDSTK.DataSource = TimKiem.TimKiemTheoMaDoiTuong(txtNoiDung.Text);
                        break;
                    case "Số điện thoại":
                        dgvDSTK.DataSource = TimKiem.TimKiemTheoSoDT(txtNoiDung.Text);
                        break;
                    case "Địa chỉ":
                        dgvDSTK.DataSource = TimKiem.TimKiemTheoDiaChi(txtNoiDung.Text);
                        break;
                    case "Email":
                        dgvDSTK.DataSource = TimKiem.TimKiemTheoEmail(txtNoiDung.Text);
                        break;
                    case "":
                        ToastNotification.Show(this,"Vui lòng chọn tìm kiếm theo..");
                        break;
                    default:
                        break;
                }
            }
        }

        private void btnTimNangCao_Click(object sender, EventArgs e)
        {
            if (txtMSSV.Text == "" && txtHoTen.Text == "" && txtGioiTinh.Text == "" && txtTenHuyen.Text == ""
                && txtTenNganh.Text == "" && txtTenKhoa.Text == "" && txtMaDoiTuong.Text == "" && txtDiaChi.Text == "")
            {
                ToastNotification.Show(this, "Bạn chưa nhập nội dung tìm kiếm nào!");
            }
            else
            {
                try
                {
                    dgvDSTK.DataSource = TimKiem.TimKiemNangCao(txtMSSV.Text, txtHoTen.Text, txtGioiTinh.Text, txtTenHuyen.Text, txtTenNganh.Text,
                        txtTenKhoa.Text, txtMaDoiTuong.Text, txtDiaChi.Text);
                }
                catch
                {

                }
            }

        }

    }
}
